package com.nbsaas.sample.controller.user;

import com.nbsaas.boot.rest.annotations.Add;
import com.nbsaas.boot.rest.annotations.Delete;
import com.nbsaas.boot.rest.annotations.Update;
import com.nbsaas.boot.rest.annotations.View;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.rest.response.PageResponse;
import com.nbsaas.boot.rest.response.ResponseObject;
import com.nbsaas.boot.rest.annotations.CreateData;
import com.nbsaas.boot.rest.annotations.UpdateData;
import com.nbsaas.sample.user.api.domain.request.StructureDataRequest;
import com.nbsaas.sample.user.api.domain.request.StructureSearchRequest;
import com.nbsaas.sample.user.api.domain.response.StructureResponse;
import com.nbsaas.sample.user.api.domain.simple.StructureSimple;
import com.nbsaas.sample.user.api.apis.StructureApi;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
*  前端控制器
*/
@RequiresAuthentication
@RestController
@RequestMapping("/structure")
public class StructureFrontController {


    @Resource
    private StructureApi structureApi;


    @RequestMapping("/search")
   public PageResponse<StructureSimple> search(StructureSearchRequest request) {
        return structureApi.search(request);
    }

    @RequestMapping("/list")
    public ListResponse <StructureSimple> list(StructureSearchRequest request) {
        return structureApi.list(request);
    }

        /**
        * 添加数据
        *
        * @param request
        * @return
        */
    @CreateData
  @RequestMapping("/create")
   public ResponseObject<StructureResponse> create(@Validated(Add.class) StructureDataRequest request) {
       return structureApi.create(request);
    }

    @UpdateData
    @RequestMapping("/update")
   public ResponseObject
    <StructureResponse> update(@Validated(Update.class) StructureDataRequest request) {
         return structureApi.update(request);
    }

     @RequestMapping("/delete")
     public ResponseObject<?> delete(@Validated(Delete.class) StructureDataRequest request) {
        return structureApi.delete(request);
    }

    @RequestMapping("/view")
    public ResponseObject <StructureResponse> view(@Validated(View.class) StructureDataRequest request) {
         return structureApi.view(request);
    }
}
